﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <title>订单完成率看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .el-form-item__label {
      color: #fff;
    }

    .header-title {
      font-size: 24px;
    }

    .el-form-item {
      margin-bottom: 0 !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <el-row>
        <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
        <el-col :span="12" class="header-title">订单完成率看板</el-col>
        <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
      </el-row>

      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="订单计划完成时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>

      <dv-border-box-11 title="订单完成率">
        <div :style="{height: chartHeight + 'px',paddingTop:'40px'}" id="finishRate"></div>
      </dv-border-box-11>

      <dv-border-box-11 title="订单完成情况">
        <div :style="{height: chartHeight + 'px',paddingTop:'40px'}" id="finishInfo"></div>
      </dv-border-box-11>

      <el-dialog :title="detail.title" :width="'95%'" :top="'10px'" :visible.sync="detail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="detail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button type="primary" icon="el-icon-download" size="mini" @click="exportDetail">
                导出
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="主制分厂" prop="factoryname"></el-table-column>
          <el-table-column label="订单号" prop="mfgordername"></el-table-column>
          <el-table-column label="计划完成时间" prop="plannedcompletiondate" width="100" :formatter="splitDate">
          </el-table-column>
          <el-table-column label="实际完成时间" prop="createdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="状态" prop="status" width='100'>
            <template slot-scope="scope" v-if="scope.row.status">
              <el-tag v-if="scope.row.status === '按时完成'" type='success'>{{scope.row.status}}</el-tag>
              <el-tag v-if="scope.row.status === '超期完成'" type='warning'>{{scope.row.status}}</el-tag>
              <el-tag v-if="scope.row.status === '未开卡'" type='info'>{{scope.row.status}}</el-tag>
              <el-tag v-if="scope.row.status === '未完成'" type='danger'>{{scope.row.status}}</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleDetailCurrentChange" :current-page="detail.queryInfo.currentPage"
          :page-sizes="[12]" :page-size="detail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="detail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        currentTime: '',
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: { selectdate: '' },
        detail: {
          dialogVisiable: false,
          queryInfo: { factoryname: '', seriesName: '', title: '', currentPage: 1, pageSize: 12 },
          dataList: [], total: 0, title: ''
        },
        rules: { selectdate: [{ required: true, message: '订单计划完成时间不能为空', trigger: 'change' }] },
        chartHeight: 360,
        chartRow: 2,
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询统计数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              echarts.dispose(document.getElementById("finishRate"));
              echarts.dispose(document.getElementById("finishInfo"));
              let chart = echarts.init(document.getElementById('finishRate'));
              let bar = echarts.init(document.getElementById('finishInfo'));
              chart.showLoading(this.loadingConfig);
              bar.showLoading(this.loadingConfig);
              const { data: { data, meta, total } } = await axios.post('../handler/board/MfgorderFinishRateDashBoard.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              chart.hideLoading();
              bar.hideLoading();

              if (meta.status === 500) { return this.$message.error(meta.msg); }
              if (data.length === 0) { return; }

              echarts.dispose(document.getElementById("finishRate"));
              echarts.dispose(document.getElementById("finishInfo"));
              chart = echarts.init(document.getElementById('finishRate'));
              bar = echarts.init(document.getElementById('finishInfo'));

              let arrFactoryname = [], arrFinishRate = [], arrIntiteFinishRate = [];
              let arrTotal = [], arrFinish = [], arrIntimeFinish = [], arrNotFinish = [], arrNotStart = [];

              for (const i of data) {
                arrFactoryname.push(i.factoryname);
                arrFinishRate.push(i.finishrate);
                arrIntiteFinishRate.push(i.intimefinishrate);
                arrTotal.push(i.total);
                arrFinish.push(i.finished);
                arrIntimeFinish.push(i.intimefinished);
                arrNotFinish.push(i.notfinished);
                arrNotStart.push(i.notstart);
              }

              let option = barOption();
              option.legend.data = ['完成率', '按时完成率'];
              option.xAxis.data = arrFactoryname;

              option.series[0] = _.merge(option.series[0], {
                name: '完成率',
                data: arrFinishRate,
                label: { color: colorList.blue.color, formatter: '{c}%' },
                itemStyle: { color: { colorStops: colorList.blue.colorStops } }
              });

              option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
                name: '按时完成率',
                data: arrIntiteFinishRate,
                label: { color: colorList.green.color },
                itemStyle: { color: { colorStops: colorList.green.colorStops } }
              });


              let option2 = barOption();
              option2.legend.data = ['计划数', '已完成', '按时完成', '未完成', '未开卡'];
              option2.xAxis.data = arrFactoryname;

              option2.series[0] = _.merge(option2.series[0], {
                name: '计划数',
                data: arrTotal,
                label: { color: colorList.blue.color },
                itemStyle: { color: { colorStops: colorList.blue.colorStops } }
              });

              option2.series[1] = _.merge(_.cloneDeep(option2.series[0]), {
                name: '已完成',
                data: arrFinish,
                label: { color: colorList.lightGreen.color },
                itemStyle: { color: { colorStops: colorList.lightGreen.colorStops } }
              });

              option2.series[2] = _.merge(_.cloneDeep(option2.series[0]), {
                name: '按时完成',
                data: arrIntimeFinish,
                label: { color: colorList.green.color },
                itemStyle: { color: { colorStops: colorList.green.colorStops } }
              });

              option2.series[3] = _.merge(_.cloneDeep(option2.series[0]), {
                name: '未完成',
                data: arrNotFinish,
                label: { color: colorList.red.color },
                itemStyle: { color: { colorStops: colorList.red.colorStops } }
              });

              option2.series[4] = _.merge(_.cloneDeep(option2.series[0]), {
                name: '未开卡',
                data: arrNotStart,
                label: { color: colorList.white.color },
                itemStyle: { color: { colorStops: colorList.white.colorStops } }
              });

              chart.setOption(option);
              bar.setOption(option2);
              bar.on('click', (params) => {
                if (params.value == 0) { return; }
                let selectdate = `${this.queryInfo.selectdate[0]}~${this.queryInfo.selectdate[1]}`;
                this.detail.queryInfo.currentPage = 1;
                this.detail.title = `${params.name} ${selectdate} 【${params.seriesName}】明细`;
                this.detail.dialogVisiable = true;
                this.detail.queryInfo.factoryname = params.name;
                this.detail.queryInfo.seriesName = params.seriesName;
                this.detail.queryInfo.title = `${params.name} ${selectdate} 【${params.seriesName}】明细`;
                this.getDetail();
              })
            }
          })
        },
        // 查询明细
        async getDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/MfgorderFinishRateDashBoard.ashx?action=getDetail', {
            type: 'getDetail',
            ...this.queryInfo,
            ...this.detail.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.detail.dataList = data;
          this.detail.total = total;
        },
        handleDetailCurrentChange(newPage) {
          this.detail.queryInfo.currentPage = newPage;
          this.getDetail();
        },
        // 导出
        exportDetail() {
          const config = {
            url: '../handler/board/MfgorderFinishRateDashBoard.ashx?action=getExportExcel',
            data: {
              type: 'getExportExcel',
              ...this.queryInfo,
              ...this.detail.queryInfo
            }
          }
          exportExcelData(config, this);
        }
      },
      mounted() {
        this.chartHeight = (window.innerHeight - 110 - this.chartRow * 40) / this.chartRow
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        const startOfMonth = dayjs().startOf('month').format('YYYY-MM-DD')
        const endOfMonth = dayjs().endOf('month').format('YYYY-MM-DD')
        this.queryInfo.selectdate = [startOfMonth, endOfMonth]
        this.getData()
      }
    })
  </script>
</body>

</html>